package utils

import (
	"log"
	"reflect"
)

func ReflectGetFieldNameInSlice(cols ...interface{}) []string{
	v := reflect.ValueOf(cols)
	t := reflect.TypeOf(cols[0])
	if t.Kind() == reflect.Ptr {
		t = t.Elem()
	}
	fname := t.Field(0).Name
	fname = fname
	kind := v.Kind()
	if kind != reflect.Slice && kind != reflect.Array {
		panic("UpdateRecodeFields only supoort slice and array type")
	}

	for i := 0; i < v.Len(); i++ {
		sv := v.Index(i)
		for sv.Kind() == reflect.Ptr || sv.Kind() == reflect.Interface {
			sv.Field(0).Elem()
			str := sv.String()
			str = str
			sv = sv.Elem()
			//t := reflect.TypeOf(sv)
			//t.Field(0).Name()
		}

	}

	return nil
}


func GetFieldName(structName interface{}) []string {
	t := reflect.TypeOf(structName)
	if t.Kind() == reflect.Ptr {
		t = t.Elem()
	}
	if t.Kind() != reflect.Struct {
		log.Println("Check type error not Struct")
		return nil
	}
	fieldNum := t.NumField()
	result := make([]string, 0, fieldNum)
	for i := 0; i < fieldNum; i++ {
		result = append(result, t.Field(i).Name)
	}
	return result
}